package sunwul.hospital.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.springframework.stereotype.Service;
import sunwul.hospital.hosp.mapper.ScheduleMapper;
import sunwul.hospital.hosp.service.ScheduleService;
import sunwul.hospital.model.model.hosp.Schedule;

import java.util.Date;
import java.util.List;

/**
 * @author sunwul
 * @date 2023/11/5 15:11:54
 * @description
 */
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService {

    /**
     * 根据医院编号与科室编号查询排班信息(分页)
     * @param current
     * @param limit
     * @param hoscode
     * @param deptcode
     * @return
     */
    @Override
    public Page<Schedule> getScheduleByPage(Long current, Long limit, String hoscode, String deptcode) {
        QueryWrapper<Schedule> wrapper =new QueryWrapper<Schedule>().eq("hoscode",hoscode).eq("depcode",deptcode);
        Page<Schedule> page = new Page<>(current, limit);
        Page<Schedule> schedulePage = baseMapper.selectPage(page, wrapper);
        return schedulePage;
    }

    /**
     * 查询排班详细信息
     * @param hoscode
     * @param deptcode
     * @param workDate
     * @return
     */
    @Override
    public List<Schedule> getScheduleDetail(String hoscode, String deptcode, String workDate) {
        Date work = new DateTime(workDate).toDate();
        QueryWrapper<Schedule> wrapper =new QueryWrapper<Schedule>().eq("hoscode",hoscode)
                .eq("depcode",deptcode).eq("work_date",work);
        return baseMapper.selectList(wrapper);
    }

    /**
     * 计算星期
     * @param dateTime
     * @return
     */
    private String getDayOfWeek(DateTime dateTime){
        String dayOfWeek = "";
        switch (dateTime.getDayOfWeek()){
            case DateTimeConstants.SUNDAY:
                dayOfWeek = "周日";
                break;
            case DateTimeConstants.MONDAY:
                dayOfWeek = "周一";
                break;
            case DateTimeConstants.TUESDAY:
                dayOfWeek = "周二";
                break;
            case DateTimeConstants.WEDNESDAY:
                dayOfWeek = "周三";
                break;
            case DateTimeConstants.THURSDAY:
                dayOfWeek = "周四";
                break;
            case DateTimeConstants.FRIDAY:
                dayOfWeek = "周五";
                break;
            case DateTimeConstants.SATURDAY:
                dayOfWeek = "周六";
                break;
        }
        return dayOfWeek;
    }
}
